#ifndef MYSWITCHBOTTON_H
#define MYSWITCHBOTTON_H

#include <QWidget>
#include <QtUiPlugin/QDesignerExportWidget>
#include <QPropertyAnimation>
#include <QMouseEvent>

class QDESIGNER_WIDGET_EXPORT mySwitchBotton : public QWidget
{
    Q_OBJECT

    Q_PROPERTY(QColor offBgColor READ offBgColor WRITE setOffBgColor NOTIFY offBgColorChanged)
    Q_PROPERTY(QColor onBgColor READ onBgColor WRITE setOnBgColor NOTIFY onBgColorChanged)

    Q_PROPERTY(QColor offIndicatorColor READ offIndicatorColor WRITE setOffIndicatorColor NOTIFY offIndicatorColorChanged)
    Q_PROPERTY(QColor onIndicatorColor READ onIndicatorColor WRITE setOnIndicatorColor NOTIFY onIndicatorColorChanged)
    Q_PROPERTY(QColor disableColor READ disableColor WRITE setDisableColor NOTIFY disableColorChanged)

    Q_PROPERTY(QString offText READ offText WRITE setOffText NOTIFY offTextChanged)
    Q_PROPERTY(QString onText READ onText WRITE setOnText NOTIFY onTextChanged)
    Q_PROPERTY(QString disableText READ disableText WRITE setDisableText NOTIFY disableTextChanged)

    Q_PROPERTY(bool isOff READ isOff WRITE setIsOff NOTIFY isOffChanged)
    Q_PROPERTY(bool isEnable READ isEnable WRITE setIsEnable NOTIFY isEnableChanged)

public:
    mySwitchBotton(QWidget *parent = 0);

    QColor offBgColor() const;
    void setOffBgColor(const QColor &newOffBgColor);

    QColor onBgColor() const;
    void setOnBgColor(const QColor &newOnBgColor);

    QColor disableColor() const;
    void setDisableColor(const QColor &newDisableColor);

    QString offText() const;
    void setOffText(const QString &newOffText);

    QString onText() const;
    void setOnText(const QString &newOnText);

    QString disableText() const;
    void setDisableText(const QString &newDisableText);

    QColor offIndicatorColor() const;
    void setOffIndicatorColor(const QColor &newOffIndicatorColor);

    QColor onIndicatorColor() const;
    void setOnIndicatorColor(const QColor &newOnIndicatorColor);


    bool isOff() const;
    void setIsOff(bool newIsOff);

    bool isEnable() const;
    void setIsEnable(bool newIsEnable);

signals:
    void offBgColorChanged();
    void onBgColorChanged();

    void offIndicatorColorChanged();
    void onIndicatorColorChanged();
    void disableColorChanged();

    void offTextChanged();
    void onTextChanged();
    void disableTextChanged();

    void isOffChanged();
    void isEnableChanged();

private:
    QColor m_offBgColor = QColor(0x979797);
    QColor m_onBgColor = QColor(0x82D94D);

    QColor m_offIndicatorColor = Qt::white;
    QColor m_onIndicatorColor = Qt::white;
    QColor m_disableColor = QColor(0xF3F3F3);

    QString m_offText = "OFF";
    QString m_onText = "ON";
    QString m_disableText;

    bool m_isOff = true;
    bool m_isEnable = true;

    int curX;
    QPropertyAnimation *animation = nullptr;

protected:
    void paintEvent(QPaintEvent *e) override;
    void mousePressEvent(QMouseEvent *event) override;
    void resizeEvent(QResizeEvent *event) override;
};

#endif // MYSWITCHBOTTON_H
